#include "DbPart.h"
#include "connectpool.h"
#include <sstream>
#include <vector>
#include "Game.h"
#include "Logic.h"
#include "RedisClient.h"
#include "util.h"


char g_szSQL[2056]={0};
#define MAX_SQL_BUF_LEN (sizeof(g_szSQL)-1)

CDbPart::CDbPart()
{
	m_dbHandler = NULL;
}

CDbPart::~CDbPart()
{
}

bool CDbPart::Get(stGameInfo& gameinfo, const std::uint32_t game, const std::uint32_t agency_id)
{
	do
	{
		std::stringstream sql;
		sql << "select agency_id, game, lauch_url, state, display_mode from agencygame where agency_id=" << agency_id << " and game=" << game << ";";
		bool ret = m_dbHandler->m_pStore->Query(sql.str().c_str());
		if (!ret)
		{
			log_error("ret is falied %d, %s",ret, sql.str().c_str());
			break;
		}
		log_debug("sql:%s", sql.str().c_str());
		unsigned long count = m_dbHandler->m_pStore->RowCount();
		if (count <= 0)
		{
			log_error("count is %lu, %s",count, sql.str().c_str());
			break;
		}
		gameinfo.agency_id = (m_dbHandler->m_pStore->GetItemLong(0, "agency_id"));
		gameinfo.game = (m_dbHandler->m_pStore->GetItemLong(0, "game"));
		gameinfo.lauch_url = (m_dbHandler->m_pStore->GetItemString(0, "lauch_url"));
		gameinfo.state = (m_dbHandler->m_pStore->GetItemLong(0, "state"));
		gameinfo.display_mode = (m_dbHandler->m_pStore->GetItemLong(0, "display_mode"));
		return true;
	} while(false);
	return false;
}


